#include<bits/stdc++.h>
using namespace std;
const int N=(1<<21)+100;
using ll=long long;
using ul=unsigned long long;
using vt=vector<int>;
int T,n,m,a[N],b[N],rk[N],f[N],v[N],L[N],R[N],ans[N];
void mg(int l,int r){
    if((l=rk[l])>(r=rk[r]))swap(l,r);
    R[l]=max(R[l],r);
}
void mg_(int l,int r){
    if((l=rk[l])>(r=rk[r]))swap(l,r);
    L[l]=min(L[l],r-1);
}
int main(){
    ios::sync_with_stdio(false),cin.tie(0);
    freopen("string.in","r",stdin);
    freopen("string.out","w",stdout);
    int i,j,k,l,r,x,y,z,rc;
    for(cin>>T;T--;){
        cin>>n;
        for(x=1;x<=n;++x)cin>>k,rk[a[x]=k+1]=x;
        rk[n+1]=rk[0]=0;
        for(x=1;x<=n+n-1;++x)cin>>b[x];
        for(x=1;x<=n+n-1;++x)if((x^b[x])&1){puts("-1");goto lc1;}
        for(x=1;x<=n;++x){
            v[x]=b[x+x-1]>>1,R[x]=x,L[x]=n;
            if(x+v[x]>n||x-v[x]<1){puts("-1");goto lc1;}
        }
        for(x=1,l=0;x<=n;++x){
            k=0;
            if(x<l+v[l])k=min(v[l+l-x],l+v[l]-x);
            if(k>v[x]){puts("-1");goto lc1;}
            while(k<v[x])++k,mg(x-k,x+k);
            if(x-k>1&&x+k<n)mg_(x-k-1,x+k+1);
        }
        for(x=1;x<n;++x){
            v[x]=b[x+x]>>1;
            if(x+v[x]>n||x-v[x]<0){puts("-1");goto lc1;}
        }
        for(x=1,l=0;x<n;++x){
            k=0;
            if(x<l+v[l])k=min(v[l+l-x],l+v[l]-x);
            if(k>v[x]){puts("-1");goto lc1;}
            while(k<v[x])++k,mg(x-k+1,x+k);
            if(x-k>0&&x+k<n)mg_(x-k,x+k+1);
        }
        for(x=n-1;x;--x)L[x]=min(L[x],L[x+1]);
        for(x=2;x<=n;++x)R[x]=max(R[x],R[x-1]);
        for(x=n-1;x;--x)
            if(R[x]>x){
                if(rk[a[x]+1]>rk[a[x+1]+1]){puts("-1");goto lc1;}
                R[x]=max(R[x],R[x+1]);
            }
        for(x=1;x<=n;++x)if(R[x]>L[x]){puts("-1");goto lc1;}
        for(x=1;x<=R[1];++x)ans[a[x]]=1;
        rc=L[1],k=1;
        for(l=R[1]+1;l<=n;l=R[l]+1){
            if(R[l]>rc||rk[a[l-1]+1]>rk[a[l]+1]){
                rc=L[l],++k;
                for(x=l;x<=R[l];++x)ans[a[x]]=k;
            }else{
                for(x=l;x<=R[l];++x)ans[a[x]]=k;
            }
        }
        if(*max_element(ans+1,ans+n+1)>26){puts("-1");goto lc1;}
        for(x=1;x<=n;++x)putchar(ans[x]+'a'-1);putchar('\n');
        lc1:;
    }
    return 0;
}